package com.wanger.swc.config.myBatisPlus.autoDDL.model;

import com.wanger.swc.util.validation.MyVerifyUtil;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

/**
 * @Author: wanger
 * @Date: 2024/10/4 20:47
 * @Description: 表模型
 */
@Data
@NoArgsConstructor
@ApiModel("数据源相关")
public class MyTable {

    @ApiModelProperty("原始数据库表名")
    private String originalTableName;

    @ApiModelProperty("数据库表名")
    private String tableName;

    @ApiModelProperty("数据库表注释")
    private String tableComment;

    @ApiModelProperty("字段导包列表")
    private Set<String> importPackages;

    @ApiModelProperty("数据库表字段列表")
    public List<MyColumn> columns;

    public MyTable(String originalTableName,
                   String tableComment,
                   Set<String> importPackages,
                   List<MyColumn> columns) {
        MyVerifyUtil.nullVerify(originalTableName, "数据库原始表名不能为空！");
        MyVerifyUtil.nullVerify(columns, "数据库表名字段列表不能为空！");
        this.originalTableName = originalTableName.toLowerCase();
        this.tableComment = tableComment;
        this.importPackages = importPackages;
        this.columns = new ArrayList<>(columns);
    }

    public MyTable(String originalTableName,
                   String tableName,
                   String tableComment,
                   Set<String> importPackages,
                   List<MyColumn> columns) {
        this(originalTableName, tableComment, importPackages, columns);
        setTableName(tableName);
    }

    public void setTableName(String tableName) {
        MyVerifyUtil.nullVerify(tableName, "数据库表名不能为空！");
        this.tableName = tableName.toLowerCase();
    }
}

